---
title: Switch
description: A SwiftUI Switch component for toggle controls.
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-ui'
packageName: '@expo/ui'
platforms: ['ios', 'tvos']
---

import APISection from '~/components/plugins/APISection';
import { APIInstallSection } from '~/components/plugins/InstallSection';
import { ContentSpotlight } from '~/ui/components/ContentSpotlight';
import { Tabs, Tab } from '~/ui/components/Tabs';

A switch component that provides toggle functionality with different visual styles.

## Installation

<APIInstallSection />

## Toggle switch

> **Note:** Also known as **Toggle**.

<Tabs>
  <Tab label="Preview">
    <ContentSpotlight
      alt="Switch component on iOS."
      src="/static/images/expo-ui/switch/ios.png"
      className="max-w-[480px]"
    />
  </Tab>
  <Tab label="Code">
    ```tsx
    import { Host, Switch } from '@expo/ui/swift-ui';

    <Host matchContents>
      <Switch
        checked={checked}
        onValueChange={checked => {
          setChecked(checked);
        }}
        color="#ff0000"
        label="Play music"
        variant="switch"
      />
    </Host>
    ```

  </Tab>
</Tabs>

> See [official SwiftUI documentation](https://developer.apple.com/documentation/swiftui/toggle) for more information.

## Checkbox

<Tabs>
  <Tab label="Preview">
    <ContentSpotlight
      alt="Picker component on iOS."
      src="/static/images/expo-ui/checkbox/ios.png"
      className="max-w-[480px]"
    />
  </Tab>
  <Tab label="Code">
    ```tsx
    import { Host, Switch } from '@expo/ui/swift-ui';

    <Host matchContents>
      <Switch
        checked={checked}
        onValueChange={checked => {
          setChecked(checked);
        }}
        label="Play music"
        variant="checkbox"
      />
    </Host>
    ```

  </Tab>
</Tabs>

> See [official SwiftUI documentation](https://developer.apple.com/documentation/swiftui/toggle) for more information.

## API

<APISection packageName="expo-ui/swift-ui/switch" apiName="Switch" />
